<?php

namespace App\Api\Eloquent;


class UserMessage extends Model
{
    public $timestamps=false;

    /*
     * 获取用户未读消息条数
     */
    public static function getMessageNum($user_id){
        $num=UserMessage::where('user_id','=',$user_id)
            ->where('readed','=','0')
            ->count();
        return $num;
    }
    /*
     * 获取用户所有消息
     */
    public static function getMessage($user_id){
        $messages=UserMessage::join('messages','messages.id','=','user_messages.message_id')
            ->where('user_messages.user_id','=',$user_id)
            ->orderBy('messages.published_at','desc')
            ->orderBy('user_messages.readed','asc')
            ->select('messages.*','user_messages.readed')
            ->get();
        return $messages;
    }
}